{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8064017e",
   "metadata": {},
   "source": [
    "if多分支"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "d82332b8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a>b\n"
     ]
    }
   ],
   "source": [
    "a=8\n",
    "b=5\n",
    "if a>b:\n",
    "    print('a>b')\n",
    "else:\n",
    "    print('a<=b')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f06d49a4",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyboardInterrupt",
     "evalue": "Interrupted by user",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-7-2903a82c6e19>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mc\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m<\u001b[0m\u001b[0mc\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'不是'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[1;32melif\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mc\u001b[0m\u001b[1;33m<=\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'不是'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\pythonprogram\\lib\\site-packages\\ipykernel\\kernelbase.py\u001b[0m in \u001b[0;36mraw_input\u001b[1;34m(self, prompt)\u001b[0m\n\u001b[0;32m    858\u001b[0m                 \u001b[1;34m\"raw_input was called, but this frontend does not support input requests.\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    859\u001b[0m             )\n\u001b[1;32m--> 860\u001b[1;33m         return self._input_request(str(prompt),\n\u001b[0m\u001b[0;32m    861\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_parent_ident\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    862\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_parent_header\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\pythonprogram\\lib\\site-packages\\ipykernel\\kernelbase.py\u001b[0m in \u001b[0;36m_input_request\u001b[1;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[0;32m    902\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mKeyboardInterrupt\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    903\u001b[0m                 \u001b[1;31m# re-raise KeyboardInterrupt, to truncate traceback\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 904\u001b[1;33m                 \u001b[1;32mraise\u001b[0m \u001b[0mKeyboardInterrupt\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Interrupted by user\"\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    905\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    906\u001b[0m                 \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlog\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwarning\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Invalid Message:\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mexc_info\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
     ]
    }
   ],
   "source": [
    "a,b,c=[int(input()),int(input()),int(input())]\n",
    "if a+b<c:\n",
    "    print('不是')\n",
    "elif a+c<=b:\n",
    "    print('不是')\n",
    "elif b+c<=a:\n",
    "    print('不是')\n",
    "else:\n",
    "    print('是三角形')\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "679a4728",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "77\n",
      " 5929\n"
     ]
    }
   ],
   "source": [
    "a=int(input())\n",
    "if a%2==1:\n",
    "    print('',a*a)\n",
    "else:\n",
    "    print('wrong')  #奇数平方"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "1983f882",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9, 25, 49, 2025]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list1=[3,5,7,32,78,96,45,28]\n",
    "new_list1=[]\n",
    "for i in list1:\n",
    "    if i%2==1:\n",
    "        new_list1.append(i**2)\n",
    "new_list1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "b1d086d8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['202221101173', '202221101174', '202221101176', '202221101177']"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list2=[\"201821102035:23\",\n",
    "\"201821102084:12\",\n",
    "\"202121132142:42\",\n",
    "\"202221092046:45\",\n",
    "\"202221101173:73\",\n",
    "\"202221101174:81\",\n",
    "\"202221101175:24\",\n",
    "\"202221101176:95\",\n",
    "\"202221101177:100\"]\n",
    "new_list2=[]\n",
    "#对所有人的成绩循环\n",
    "for i in list2:\n",
    "    #学号成绩分开\n",
    "    person_list=i.split(':')\n",
    "    #提取成整数，判断\n",
    "    if int(person_list[-1])>=60:\n",
    "        new_list2.append(person_list[0])\n",
    "new_list2\n",
    "        \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0b4f408c",
   "metadata": {},
   "source": [
    "列表推导式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "e4c86427",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 2, 4, 6, 8]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list4=[]\n",
    "for i in range(0,10,2):\n",
    "    list4.append(i)\n",
    "list4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "3999544a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 2, 4, 6, 8]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list3=[i for i in range(0,10,2)]\n",
    "list3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "82c003a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 9, 25, 49, 81]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#利用列表推导式：1，3，5，7，9的平方\n",
    "list4=[i*i for i in range(1,10,2)]\n",
    "list4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2bead8b1",
   "metadata": {},
   "outputs": [],
   "source": [
    "list1=[3,5,7,32,78,96,45,28]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "119c5fdb",
   "metadata": {},
   "source": [
    "break,continue,pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "82501564",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "continue之前\n",
      "0\n",
      "continue之前\n",
      "1\n",
      "continue之前\n",
      "2\n",
      "continue之前\n",
      "3\n",
      "continue之前\n",
      "4\n",
      "continue之前\n",
      "5\n",
      "continue之前\n",
      "6\n",
      "continue之前\n",
      "7\n",
      "continue之前\n",
      "8\n",
      "continue之前\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "for i in range(10):\n",
    "    print('continue之前')\n",
    "    print(i)\n",
    "    continue   #中止当前循环后面的语句，但不影响大的循环\n",
    "    print('continue之后')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "b783e5b1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "break之前\n",
      "0\n"
     ]
    }
   ],
   "source": [
    "for i in range(3):\n",
    "    print('break之前')\n",
    "    print(i)\n",
    "    break\n",
    "    print('break之后')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "309ce5cb",
   "metadata": {},
   "outputs": [],
   "source": [
    "#人：1/2，1/3，原点，路的长度是1，随机打开一个门\n",
    "import random\n",
    "door=[1/2,1/3,0]\n",
    "lu=0\n",
    "CD=[]\n",
    "while True:\n",
    "    c_d=random.randint(0,2)\n",
    "    CD.append(c_d)\n",
    "    if c_d==2:\n",
    "        lu=0\n",
    "    else:\n",
    "        lu"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c60bf7b9",
   "metadata": {},
   "source": [
    "函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ae0526bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "  #最简单的函数\n",
    "def name():   #def XXXX():  规定\n",
    "    ...      #函数内部的信息\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "5c8e0954",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "haha\n"
     ]
    }
   ],
   "source": [
    "def name():\n",
    "    print('haha')   #没有返回值，无法接收结果\n",
    "a=name()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "9b07e2f5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'haha'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def name():\n",
    "    return'haha'    #有return才可以返回结果，参数才有东西接收\n",
    "a=name()\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "17f061cb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'9527,你好'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def name(x):\n",
    "    return f'{x},你好'\n",
    "a=name('9527')   #将9527赋值给X后，X进行函数运算\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "bf933c57",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def name(x):\n",
    "    return x**2+2*x-1\n",
    "name(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "2bcf9a57",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "是的\n"
     ]
    }
   ],
   "source": [
    "def fun(x):\n",
    "    a,b,c=x\n",
    "    if a+b>c and a+c>b and b+c>a:\n",
    "        print('是的')\n",
    "    else:\n",
    "        print('不是')\n",
    "fun([4,2,3])        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "d3470b51",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def fun3(x,y):   #矩形面积\n",
    "    return x*y\n",
    "fun3(3,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "c619ec27",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "24"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def fun3(x,y,z):\n",
    "    return x*y*z\n",
    "fun3(3,2,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "8903f04e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'znuniversity的hahaha'"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def fun3(name,school):  #或指定参数，(name,school=znuniversity)\n",
    "    return f'{school}的{name}'\n",
    "fun3('hahaha','znuniversity')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "7880cc14",
   "metadata": {},
   "outputs": [],
   "source": [
    "#给定一个数，求1+2+3+....+这个数\n",
    "def plus(x):\n",
    "    list1=[i for i in range(1,x+1)]\n",
    "    return sum(list1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "c8f54cf6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5050"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fun=lambda x:sum([i for i in range(1,x+1)])\n",
    "fun(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "9c748ceb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "54"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fun=lambda x,y,z:x+y+z\n",
    "fun(17,18,19)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "df18d30c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "125"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fun=lambda x,y:x**y\n",
    "fun(5,3)             #求任意数x的y次方"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fe3588f7",
   "metadata": {},
   "source": [
    "模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "96214d21",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "import keyboard\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "35f4c800",
   "metadata": {},
   "source": [
    "自己打包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "cb01652a",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named '哈哈哈哈哈哈'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-48-2b55a562e057>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m#方便将自己的函数进行打包，可以重复调用\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0m哈哈哈哈哈哈\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m \u001b[0m哈哈哈哈哈哈\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfun\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m100\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named '哈哈哈哈哈哈'"
     ]
    }
   ],
   "source": [
    "#方便将自己的函数进行打包，可以重复调用\n",
    "import 哈哈哈哈哈哈\n",
    "哈哈哈哈哈哈.fun(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7b6879a6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
